#include <stdio.h>
#include <stdlib.h>
#include "ExtremeC_examples_chapter8_2_person.h"
#include "ExtremeC_examples_chapter8_2_student.h"

int main(int argc, char** argv)
{
    //创建并构造学生对象
    struct student_t* student = student_new();
    student_ctor(student, "John", "Doe", 1987, "TA5667", 134);

    //使用 person 的行为函数从 student 对象中读取 person 的属性
    char buffer[32];

    //向上转换为父类的指针
    struct person_t* person_ptr = (struct person_t*)student;
    person_get_first_name(person_ptr, buffer);
    printf("First name: %s\n", buffer);

    person_get_last_name(person_ptr, buffer);
    printf("Last name: %s\n", buffer);
    printf("Birth year: %d\n", person_get_brith_year(person_ptr));

    //读取专属于 student 对象的属性
    student_get_student_number(student, buffer);
    printf("Student number: %s\n", buffer);

    printf("Passed credits: %d\n", student_get_passed_credits(student));

    //析构并释放学生对象
    student_dtor(student);
    free(student);
}